<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>课程成绩分析 - 在线考试系统</title>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/css/all.min.css">
    <script src="/js/echarts.min.js"></script>
    <style>
        :root {
            --primary: #4361ee;
            --secondary: #3f37c9;
            --success: #4caf50;
            --warning: #ff9800;
            --danger: #f44336;
            --info: #2196f3;
            --light: #f8f9fa;
            --dark: #343a40;
            --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            --transition: all 0.3s ease;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f5f7fb;
            color: #333;
            min-height: 100vh;
        }

        .navbar {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            padding: 0.8rem 1rem;
        }

        .navbar-brand {
            font-weight: 700;
            font-size: 1.5rem;
            display: flex;
            align-items: center;
        }

        .navbar-brand i {
            margin-right: 10px;
            font-size: 1.8rem;
        }

        .nav-link {
            color: rgba(255, 255, 255, 0.85) !important;
            font-weight: 500;
            padding: 0.5rem 1rem !important;
            border-radius: 4px;
            margin: 0 3px;
            transition: var(--transition);
        }

        .nav-link:hover, .nav-link.active {
            background-color: rgba(255, 255, 255, 0.15);
            color: white !important;
        }

        .main-content {
            padding: 2rem 0;
        }

        .page-header {
            background: white;
            border-radius: 15px;
            padding: 1.5rem;
            box-shadow: var(--card-shadow);
            margin-bottom: 2rem;
            position: relative;
            overflow: hidden;
        }

        .page-header::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 5px;
            height: 100%;
            background: linear-gradient(135deg, var(--primary), var(--secondary));
        }

        .page-title {
            font-weight: 700;
            margin-bottom: 0.5rem;
            color: var(--dark);
        }

        .page-subtitle {
            color: #6c757d;
            margin-bottom: 0;
        }

        .course-card {
            background: white;
            border-radius: 12px;
            box-shadow: var(--card-shadow);
            margin-bottom: 2rem;
            overflow: hidden;
            transition: var(--transition);
        }

        .course-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
        }

        .course-header {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            color: white;
            padding: 1.5rem;
            position: relative;
        }

        .course-header::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 5px;
            height: 100%;
            background: rgba(255, 255, 255, 0.3);
        }

        .course-name {
            font-size: 1.5rem;
            font-weight: 700;
            margin-bottom: 0.5rem;
        }

        .course-stats {
            display: flex;
            gap: 2rem;
            margin-top: 1rem;
        }

        .stat-item {
            text-align: center;
        }

        .stat-number {
            font-size: 1.5rem;
            font-weight: 700;
            display: block;
        }

        .stat-label {
            font-size: 0.9rem;
            opacity: 0.9;
        }

        .course-body {
            padding: 1.5rem;
        }

        .chart-container {
            height: 300px;
            width: 100%;
        }

        .score-table {
            margin-top: 1.5rem;
        }

        .score-table th {
            background-color: var(--light);
            border: none;
            font-weight: 600;
        }

        .score-table td {
            border: none;
            border-bottom: 1px solid rgba(0, 0, 0, 0.05);
            vertical-align: middle;
        }

        .score-badge {
            padding: 0.25rem 0.75rem;
            border-radius: 20px;
            font-size: 0.85rem;
            font-weight: 600;
        }

        .score-excellent {
            background-color: rgba(76, 175, 80, 0.1);
            color: var(--success);
        }

        .score-good {
            background-color: rgba(33, 150, 243, 0.1);
            color: var(--info);
        }

        .score-average {
            background-color: rgba(255, 152, 0, 0.1);
            color: var(--warning);
        }

        .score-poor {
            background-color: rgba(244, 67, 54, 0.1);
            color: var(--danger);
        }

        .btn-primary {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            border: none;
            padding: 0.5rem 1.5rem;
            font-weight: 600;
            border-radius: 8px;
            transition: var(--transition);
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(67, 97, 238, 0.4);
        }

        .loading {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 200px;
        }

        .spinner-border {
            color: var(--primary);
        }

        .back-btn {
            background: rgba(255, 255, 255, 0.2);
            border: 1px solid rgba(255, 255, 255, 0.3);
            color: white;
            padding: 0.5rem 1rem;
            border-radius: 6px;
            text-decoration: none;
            transition: var(--transition);
        }

        .back-btn:hover {
            background: rgba(255, 255, 255, 0.3);
            color: white;
        }

        @media (max-width: 768px) {
            .course-stats {
                flex-direction: column;
                gap: 1rem;
            }
            
            .chart-container {
                height: 250px;
            }
        }

        .footer {
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            color: white;
            padding: 2rem 0;
            margin-top: auto;
        }
        .student .footer {
            background: linear-gradient(135deg, var(--primary), #3a0ca3);
        }
        .copyright {
            text-align: center;
            padding-top: 1.5rem;
            margin-top: 1.5rem;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
            color: rgba(255, 255, 255, 0.7);
            font-size: 0.9rem;
        }
    </style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark">
    <div class="container">
        <a class="navbar-brand" href="/student/home">
            <i class="fas fa-graduation-cap"></i>在线考试系统
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav me-auto">
                <li class="nav-item">
                    <a class="nav-link active" href="/home/manage"><i class="fas fa-home"></i> 主页</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/student/exam/list"><i class="fas fa-pen-alt"></i> 考试信息</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/student/score/analysis"><i class="fas fa-chart-line"></i> 成绩分析</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/student/resources"><i class="fas fa-book-open"></i> 学习资源</a>
                </li>
            </ul>

            <ul class="navbar-nav ms-auto">
                <li class="nav-item">
                    <a class="nav-link" href="/student/profile/manage">
                        <i class="fas fa-user-circle"></i> 个人信息
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="/logout">
                        <i class="fas fa-sign-out-alt"></i> 退出登录
                    </a>
                </li>
            </ul>
        </div>
    </div>
</nav>

<div class="main-content">
    <div class="container">
        <div class="page-header">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    <h1 class="page-title">课程成绩分析</h1>
                    <p class="page-subtitle">详细分析各课程的学习表现</p>
                </div>
                <a href="/student/score/analysis" class="back-btn">
                    <i class="fas fa-arrow-left me-2"></i>返回成绩分析
                </a>
            </div>
        </div>

        <div id="courseAnalysisContainer">
            <div class="loading">
                <div class="spinner-border" role="status">
                    <span class="visually-hidden">加载中...</span>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 页脚 -->
<footer class="footer student">
    <div class="container text-center py-4">
        <a href="https://gitee.com/sorrymaker04/onlineexam-workload" target="_blank" class="text-white mx-2">
            <i class="fab fa-github fa-2x"></i>
        </a>
        <div class="copyright mt-2">
            &copy; 2025 版权所有 北城在线考试系统小组 12 Team
        </div>
    </div>
</footer>
<script src="/js/bootstrap.bundle.min.js"></script>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        loadCourseAnalysis();
    });
    
    function loadCourseAnalysis() {
        const container = document.getElementById('courseAnalysisContainer');
        
        fetch('/student/score/api/course-analysis')
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    const courses = data.data;
                    if (courses.length === 0) {
                        container.innerHTML = '<div class="text-center p-5"><i class="fas fa-book-open fa-3x text-muted mb-3"></i><p class="text-muted">暂无课程成绩数据</p></div>';
                        return;
                    }
                    
                    let html = '';
                    courses.forEach((course, index) => {
                        html += `
                            <div class="course-card">
                                <div class="course-header">
                                    <div class="course-name">${course.courseName}</div>
                                    <div class="course-stats">
                                        <div class="stat-item">
                                            <span class="stat-number">${course.averageScore.toFixed(1)}</span>
                                            <span class="stat-label">平均成绩</span>
                                        </div>
                                        <div class="stat-item">
                                            <span class="stat-number">${course.examCount}</span>
                                            <span class="stat-label">考试次数</span>
                                        </div>
                                        <div class="stat-item">
                                            <span class="stat-number">${getScoreLevel(course.averageScore, course.totalScores[0])}</span>
                                            <span class="stat-label">成绩等级</span>
                                        </div>
                                    </div>
                                </div>
                                <div class="course-body">
                                    <div class="row">
                                        <div class="col-lg-8">
                                            <h5 class="mb-3">成绩趋势</h5>
                                            <div id="courseChart${index}" class="chart-container"></div>
                                        </div>
                                        <div class="col-lg-4">
                                            <h5 class="mb-3">考试记录</h5>
                                            <div class="table-responsive">
                                                <table class="table score-table">
                                                    <thead>
                                                        <tr>
                                                            <th>考试名称</th>
                                                            <th>成绩</th>
                                                            <th>等级</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        ${generateScoreTableRows(course.scores, course.examNames, course.totalScores)}
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        `;
                    });
                    
                    container.innerHTML = html;
                    
                    // 初始化每个课程的图表
                    courses.forEach((course, index) => {
                        initCourseChart(index, course);
                    });
                } else {
                    container.innerHTML = '<div class="text-center p-5 text-danger">加载失败</div>';
                }
            })
            .catch(error => {
                console.error('加载课程分析失败:', error);
                container.innerHTML = '<div class="text-center p-5 text-danger">加载失败</div>';
            });
    }
    
    function getScoreLevel(score, totalScore = 100) {
        if (totalScore === 0) return '无效';
        const percent = score / totalScore;
        if (percent >= 0.9) return '优秀';
        if (percent >= 0.8) return '良好';
        if (percent >= 0.7) return '中等';
        if (percent >= 0.6) return '及格';
        return '不及格';
    }
    
    function getScoreClass(score, totalScore = 100) {
        if (totalScore === 0) return 'score-poor';
        const percent = score / totalScore;
        if (percent >= 0.9) return 'score-excellent';
        if (percent >= 0.8) return 'score-good';
        if (percent >= 0.7) return 'score-average';
        return 'score-poor';
    }
    
    function generateScoreTableRows(scores, examNames, totalScores) {
        if (!scores || !examNames || scores.length === 0) {
            return '<tr><td colspan="3" class="text-center text-muted">暂无考试记录</td></tr>';
        }
        let rows = '';
        for (let i = 0; i < Math.min(scores.length, examNames.length); i++) {
            const score = scores[i];
            const examName = examNames[i];
            const totalScore = (totalScores && totalScores[i]) ? totalScores[i] : 100;
            const scoreClass = getScoreClass(score, totalScore);
            const scoreLevel = getScoreLevel(score, totalScore);
            rows += `
                <tr>
                    <td>${examName}</td>
                    <td><strong>${score.toFixed(1)}</strong>/${totalScore}</td>
                    <td><span class="score-badge ${scoreClass}">${scoreLevel}</span></td>
                </tr>
            `;
        }
        return rows;
    }
    
    function initCourseChart(index, course) {
        const chartDom = document.getElementById(`courseChart${index}`);
        if (!chartDom) return;
        
        const chart = echarts.init(chartDom);
        
        const option = {
            title: {
                text: '成绩变化趋势',
                left: 'center',
                textStyle: {
                    fontSize: 14,
                    fontWeight: 'bold'
                }
            },
            tooltip: {
                trigger: 'axis',
                formatter: function(params) {
                    const data = params[0];
                    return `${data.name}<br/>成绩: ${data.value}分`;
                }
            },
            xAxis: {
                type: 'category',
                data: course.examNames || [],
                axisLabel: {
                    rotate: 45,
                    fontSize: 10
                }
            },
            yAxis: {
                type: 'value',
                name: '成绩',
                min: 0,
                max: 100
            },
            series: [{
                name: '成绩',
                type: 'line',
                data: course.scores || [],
                smooth: true,
                lineStyle: {
                    color: '#4361ee',
                    width: 3
                },
                itemStyle: {
                    color: '#4361ee'
                },
                areaStyle: {
                    color: {
                        type: 'linear',
                        x: 0, y: 0, x2: 0, y2: 1,
                        colorStops: [{
                            offset: 0, color: 'rgba(67, 97, 238, 0.3)'
                        }, {
                            offset: 1, color: 'rgba(67, 97, 238, 0.1)'
                        }]
                    }
                }
            }]
        };
        
        chart.setOption(option);
        
        // 响应式调整
        window.addEventListener('resize', function() {
            chart.resize();
        });
    }
</script>
</body>
</html> 